pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File( "${pluginHome}/scripts/CloudToolsInit.groovy" )

target('default': "Enales the BRB Page") {
	enableSlaveBackups()
}

target(enableSlaveBackups: "The implementation task") {
	depends( initCloudToolsService)
	def awsProperties = cloudToolsService.makeAWSProperties()
	
    cloudToolsService.withCluster { clusterManager, clusterName, cluster ->
		if(System.getProperty("cloudtools.slave")){
			def slaveInstanceId = System.getProperty("cloudtools.slave")
			def bucket = awsProperties.accessKey + "." + System.getProperty("grails.env") + "-" + grailsAppName + "-" + clusterName + "-backups"
			cluster.getClusterInstance().getDatabaseTier().configureSlaveBackup(slaveInstanceId, bucket, "backup-slave");
			event('StatusFinal', ['Done backing up ' + slaveInstanceId])
		}else{
			event('StatusError', ["cloudtools.slave was not specified.  Example:\ngrails -Dcloudtools.slave=<instance id> cloud-tools-enable-slave-backups"])
		}
	}
}
